import cv2

red = (0, 0, 255)


# ==============================
# 轮廓面积
# ==============================
def test1():
    #
    src = cv2.imread('graph.png')

    # 转换颜色空间
    img = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
    # 二值化
    ret, img = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)
    # 查找轮廓
    contours, hierarchy = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

    # 遍历轮廓
    for i, contour in enumerate(contours):
        area = cv2.contourArea(contour[i])
        print('>>>>>> 轮廓面积: ', type(area), area)
